


/*******************************************************************************
File: agg_data_figures
Purpose: Plot the fit of the Phillips curve at the aggregate level
Last Update: October 1st, 2021.
*******************************************************************************/
clear all
set more off
 set matsize 800
eststo clear
clear matrix

 
* Set the local name with your name.
local name = "juan"

* set your path under your name
if "`name'" == "juan" { 
cd "/Users/juanherreno/Dropbox/Investigacion/StateLevelCPIs/Stata"
}

if  "`name'" == "emi" {
cd "e:/mydocs/dropbox/StateLevelCPIs/stata"
}

if  "`name'" == "joe" {
cd "/Users/joehazell/Dropbox/StateLevelCPIs/Stata/"
}

if  "`name'" == "jon" {
cd ""
}

if "`name'" == "juan_pc" { 
cd "C:/Users/jdh2181/Dropbox/Investigacion/StateLevelCPIs/stata/"
}

* Figure 1 in the paper. Loads data from FRED.

import delimited "Code/code_to_share/data_stock_watson_fred.csv", clear
gen year = substr(date,1,4)
gen month = substr(date,6,2)
destring year, replace
destring month, replace
gen time = year + (month-1)/12
gen time_ts = _n
tsset time_ts
gen pi_pce_ma = (1/4)*(pcepi_pc1 + l.pcepi_pc1 + l2.pcepi_pc1 + l3.pcepi_pc1)
gen pi_pce_core_ma = (1/4)*(pcepilfe_pc1 + l.pcepilfe_pc1 + l2.pcepilfe_pc1 + l3.pcepilfe_pc1)
gen delta_pi_pce_ma = pi_pce_ma - l4.pi_pce_ma
gen delta_pi_pce_core_ma = pi_pce_core_ma - l4.pi_pce_core_ma
gen un_rate_gap = unrate - nroust
gen un_rate_gap_ma = (1/4)*(un_rate_gap + l.un_rate_gap + l2.un_rate_gap + l3.un_rate_gap)
twoway (scatter delta_pi_pce_ma un_rate_gap_ma if year <= 1983) (scatter delta_pi_pce_ma un_rate_gap_ma if year > 1983 & year <= 1999) (scatter delta_pi_pce_ma un_rate_gap_ma if year >= 2000 & year <= 2019) 
graph save "Code/code_to_share/Graphs/stock_watson_2019", replace
// generate lines of fit
qui reg delta_pi_pce_ma un_rate_gap_ma if year <= 1983
predict fit_83, xb
qui reg delta_pi_pce_ma un_rate_gap_ma if year > 1983 & year <= 1999
predict fit_84_99, xb
qui reg delta_pi_pce_ma un_rate_gap_ma if year >= 2000 & year <= 2019
predict fit_2000_99, xb
keep delta_pi_pce_ma un_rate_gap_ma year time month fit*
keep if year <= 2019
keep if delta_pi_pce_ma != . 
twoway (scatter delta_pi_pce_ma un_rate_gap_ma if year <= 1983) (scatter delta_pi_pce_ma un_rate_gap_ma if year > 1983 & year <= 1999) (scatter delta_pi_pce_ma un_rate_gap_ma if year >= 2000 & year <= 2019) (line fit_83 fit_84_99 fit_2000_99 un_rate_gap_ma)


use "Code/code_to_share/agg_data.dta", clear
keep if year >= 1978
keep if year <= 2017
// Fix format for the figures.
label var spf_cpi_lt "SPF CPI LT Inflation Expectations"
label var time "Time"
label var date "Time"

* Figure 2 in the paper
line  pi_cpi_rs_core spf_cpi_lt time, xlabel(1976(5)2014,labsize(large)) ylabel(,labsize(large))    graphregion(color(white))  xtit(,  size(large)) ytit(, size(large))
graph save "Code/code_to_share/Graphs/Des_CPI_rs_lt", replace

* Figure 3 in the paper
line  pi_cpi_all spf_pgdp time, xlabel(1976(5)2014,labsize(large)) ylabel(-5(5)15,labsize(large))   ysc(r(-5 15))  graphregion(color(white))  xtit(,  size(large)) ytit(, size(large))
graph save "Graphs/Des_CPIAll_Exp", replace
graph export "Graphs/Des_CPIAll_Exp.png", replace

line  pi_cpi_lessfe spf_pgdp time, xlabel(1976(5)2014,labsize(large)) ylabel(-5(5)15,labsize(large))   ysc(r(-5 15))  graphregion(color(white)) xtit(,  size(large)) ytit(, size(large))
graph save "Graphs/Des_CPICore_Exp", replace
graph export "Graphs/Des_CPICore_Exp.png", replace

line  pi_cpi_rs_core spf_pgdp time,  xlabel(1976(5)2014,labsize(large)) ylabel(-5(5)15,labsize(large))   ysc(r(-5 15)) graphregion(color(white)) xtit(,  size(large)) ytit(, size(large))
graph save "Graphs/Des_CPICoreRS_Exp", replace
graph export "Graphs/Des_CPICoreRS_Exp.png", replace

line  pi_pce_core spf_pgdp time,  xlabel(1976(5)2014,labsize(large)) ylabel(-5(5)15,labsize(large))   ysc(r(-5 15)) graphregion(color(white)) xtit(,  size(large)) ytit(, size(large))
graph save "Graphs/Des_PCECore_Exp", replace
graph export "Graphs/Des_PCECore_Exp.png", replace

